from app import db


class Article(db.Model):
    __tablename__ = 'cms_article'
    article_pk = db.Column(db.Integer,primary_key=True,autoincrement=True)
    article_title = db.Column(db.String)
    article_titleimg = db.Column(db.String)
    article_ftitle = db.Column(db.String)
    article_createtime = db.Column(db.String)
    article_sendtime = db.Column(db.String)
    article_author = db.Column(db.String)
    article_source = db.Column(db.String)
    article_istop = db.Column(db.String)
    article_state = db.Column(db.String)
    article_content = db.Column(db.String)
    article_type = db.Column(db.String)
    article_click = db.Column(db.String)
    article_url = db.Column(db.String)
    article_upauthor = db.Column(db.String)
    article_uptime = db.Column(db.String)

    def __repr__(self):
        return '<Article %r>' % self.article_pk
        
    #将查询出的list数据转换为字典，否则无法序列化
    def to_dict(items):
        lic = []
        for item in items:
            lic.append(
                {
                    'article_pk': item.article_pk,
                    'article_title' : item.article_title,
                    'article_titleimg' : item.article_titleimg,
                    'article_ftitle' : item.article_ftitle,
                    'article_createtime' : item.article_createtime,
                    'article_sendtime' : item.article_sendtime,
                    'article_author' : item.article_author,
                    'article_source' : item.article_source,
                    'article_istop': item.article_istop,
                    'article_state' : item.article_state,
                    'article_content' : item.article_content,
                    'article_type' : item.article_type,
                    'article_click': item.article_click,
                    'article_url' : item.article_url,
                    'article_upauthor' : item.article_upauthor,
                    'article_uptime' : item.article_uptime
                }
            )
        return lic